<template>
    <div class="v-modal">
        <dialog v-show="isShow" id="v-modal-id" class="v-modal-box">
            <button type="button" class="v-modal-close" @click="onClose">
                <span class="v-modal-close-x">
                    <a-icon type="close" />
                </span>
            </button>
            <div class="v-modal-header">
                <slot name="header">
                    <span class="icon-common icon-question" v-if="iconType === 'question'"><a-icon type="question-circle" /></span>
                    <span class="icon-common icon-info" v-if="iconType === 'info'"><a-icon type="info-circle" /></span>
                    <span class="icon-common icon-success" v-if="iconType === 'success'"><a-icon type="check-circle" /></span>
                    <span class="icon-common icon-error" v-if="iconType === 'error'"><a-icon type="close-circle" /></span>
                    <span class="icon-common icon-warning" v-if="iconType === 'warning'"><a-icon type="exclamation-circle" /></span>
                    <span>{{ title }}</span>
                </slot>
            </div>
            <div class="v-modal-content">
                <slot name="content">
                    <span>{{ message }}</span>
                </slot>
            </div>
            <div class="v-modal-footer">
                <slot name="footer">
                    <div class="footer-operate">
                        <a-button  @click="onClose">取消</a-button>
                        <a-button @click="onOK" type="primary">确定</a-button>
                    </div>
                </slot>
            </div>
        </dialog>
    </div>
</template>

<script>
export default {
    name: "v-modal",
    props: {
        title: {
            type: String,
            default: 'Title'
        },
        message: {
            type: String,
            default: 'Content of the modal'
        },
        // question info success error warning
        iconType: {
            type: String,
            default: ''
        }
    },
    data() {
        return {
            isShow: false,
            modalId: '',
        };
    },
    methods: {
        onShow() {
            this.isShow = true;
            this.modalId.showModal();
        },
        onClose() {
            this.isShow = false;
            this.modalId.close();
        },
        onOK() {
            this.$emit("ok");
        }
    },
    mounted() {
        this.modalId = document.querySelector("#v-modal-id");
    },
};
</script>

<style lang="less" scoped>
.v-modal {
    .v-modal-box {
        position: relative;
        min-width: 400px;
        padding: 0;
        background-color: #fff;
        background-clip: padding-box;
        border: 0;
        border-radius: 4px;
        box-shadow: 0 4px 12px #00000026;
        .v-modal-close {
            position: absolute;
            top: 0;
            right: 0;
            z-index: 10;
            padding: 0;
            color: rgba(0,0,0,.45);
            font-weight: 700;
            line-height: 1;
            text-decoration: none;
            background: transparent;
            border: 0;
            outline: 0;
            cursor: pointer;
            transition: color .3s;
            .v-modal-close-x{
                display: block;
                width: 56px;
                height: 56px;
                font-size: 16px;
                font-style: normal;
                line-height: 56px;
                text-align: center;
                text-transform: none;
                text-rendering: auto;
            }
            :hover{
                color: rgba(0,0,0,.75);
                text-decoration: none;
            }
        }
        .v-modal-header {
            padding: 16px 24px;
            color: rgba(0, 0, 0, 0.65);
            background: #fff;
            border-bottom: 1px solid #e8e8e8;
            border-radius: 4px 4px 0 0;
            display: flex;
            align-items: center;
            .icon-common{
                font-size: 22px;
                display: flex;
                margin-right: 8px;
            }
            .icon-question{
                color: #faad14;
            }
            .icon-info{
                color: #1890ff;
            }
            .icon-success{
                color: #52c41a;
            }
            .icon-error{
                color: #f5222d;
            }
            .icon-warning{
                color: #faad14;
            }
        }
        .v-modal-content {
            padding: 24px;
            font-size: 14px;
            line-height: 1.5;
            word-wrap: break-word;
        }
        .v-modal-footer {
            padding: 10px 16px;
            text-align: right;
            background: transparent;
            border-top: 1px solid #e8e8e8;
            border-radius: 0 0 4px 4px;
            .footer-operate{
                width: 100%;
                height: 100%;
            }
        }
        &::backdrop{
            background-color: #00000073;
        }
    }
}
</style>